#!/bin/bash
#
# Copyright (C) 2025, Cyrus Li (e21920076@126.com). All rights reserved.
#

#
# A handy script to review power infomation for my laptop HBri721
#

FILE=$(readlink -f "${BASH_SOURCE[0]}")
CDIR=$(dirname "$FILE")
NAME=$(basename "$FILE")
TMPDIR=${TMPDIR:-"/tmp"}

F=$TMPDIR/${NAME}.out.$$
trap "rm -f $F" EXIT

upower -i /org/freedesktop/UPower/devices/battery_BATT > $F
[[ $1 == "-v" ]] && cat $F && exit 0

grep -E 'state:|percentage:|capacity:|time to empty:|time to full:' $F | \
    tr -s ' ' ' ' | \
    sed 's/^/>>>/g'
exit $?
